package j.todo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

public class SBItemButton extends Button {
	private Context context;
	private int width, height, x, y;
	private int x1, x2, y1, y2;
	private RelativeLayout.LayoutParams itemParams;
	private OnTouchListener itemButtonTouchListener;
	private SBItemButton itemSelected;
	private String line, prior;

	public SBItemButton(Context context) {
		super(context);
		this.context = context;
		init();
	}

	public void init() {
		width = 100;
		height = 100;
		x = 0;
		y = 0;
		// index = SBDefineConstant.getInstance().getItemList().size();
		setOnTouchListener(new ItemButtonTouchListener());
		// setOnLongClickListener(new ItemButtonLongClickListener());
		setBackgroundResource(R.drawable.memo);
	}

	public void setPrior(String prior) {
		this.prior = prior;
		if ("c".equalsIgnoreCase(prior)) {
			width = 50;
			height = 50;
		} else if ("b".equalsIgnoreCase(prior)) {
			width = 100;
			height = 100;
		} else if ("a".equalsIgnoreCase(prior)) {
			width = 150;
			height = 150;
		} else {
			width = 100;
			height = 500;

		}
	}

	public void setLine(String line) {
		this.line = line;
	}

	public String getLine() {
		return line;
	}

	public class Image {
		Uri imageUri;
	}

	public String getPrior() {
		return prior;
	}

	public int getItemWidth() {
		return width;
	}

	public int getItemHeight() {
		return height;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void setX(int x) {
		this.x = x;
	}

	public void setY(int y) {
		this.y = y;
	}

	public class ItemButtonTouchListener implements OnTouchListener {
		public boolean onTouch(View v, MotionEvent event) {
			itemSelected = (SBItemButton) v;
			itemParams = new RelativeLayout.LayoutParams(width, height);
			itemParams.setMargins(x, y, 0, 0);
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				x1 = (int) event.getX();
				y1 = (int) event.getY();
				v.bringToFront();
				break;
			case MotionEvent.ACTION_MOVE:
				x2 = (int) event.getX();
				y2 = (int) event.getY();

				itemSelected.setX(itemSelected.getX() + (x2 - x1));
				itemSelected.setY(itemSelected.getY() + (y2 - y1));
				itemParams.setMargins(itemSelected.getX(), itemSelected.getY(),
						0, 0);
				if (SBAttachActivity.EDIT_MODE) {
					itemSelected.setLayoutParams(itemParams);
				}
				break;
			case MotionEvent.ACTION_UP:
			}
			return false;

		}
	}

}
